<template>
  <div>
    <h2 align="center">投资项目修改页面</h2>
    <table class="table table-bordered">
      <tr>
        <td>投资名称</td>
        <td>
          <input type="text" v-model="upData.T_Name" >
        </td>
      </tr>

      <tr>
        <td>投资总金额</td>
        <td>
          <input type="text" v-model="upData.T_Total" >
        </td>
      </tr>

      <tr>
        <td></td>
        <td>
          <input type="button" value="确认修改" @click="addInfo" >
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">

import {reactive,toRefs,onMounted} from 'vue'
import { useRouter,useRoute } from 'vue-router'
import axios from 'axios'

let router = useRouter()

let route = useRoute()

//数据
let data = reactive({
  upData:{
    T_Name:'',
    T_Total:''
  }
})
//解构
let {upData} = toRefs(data)

//回显
onMounted(()=>{
  BackInfo()
})

//回显方法
const BackInfo =()=>{
  axios({
    url:'/api/Invest/Find',
    method:'get',
    params:{
      T_Id:route.query.T_Id
    }
  }).then(res=>{
    console.log(res);
    upData.value=res.data.data
  }).catch(err=>{
    console.log(err);
  })
}

//修改方法
const addInfo =()=>{
  //非空判断
  if(upData.value.T_Name==""){
    return alert('投资名称不能为空')
  } 
  if(upData.value.T_Total==""){
    return alert('投资总金额不能为空')
  }
  //判断是否为数字
  if(isNaN(upData.value.T_Total)){
    return alert('投资总金额必须为数字')
  }  
  if(upData.value.T_Total<100000){
    return alert('投资总金额必须大于100000')
  }

  axios({
    url:'/api/Invest/UpInfo',
    method:'post',
    data:upData.value
  }).then(res=>{
     if(res.data.data >0){
      alert('修改成功')
      router.push({
        path:'/showInvest'
      })
    }else{
      alert('修改失败')
    }
  })
}

</script>

<style scoped>

</style>